package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogSkinVolumeEmbroideryFix;
import com.yanqu.road.entity.log.LogSkinVolumePiecesGet;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/5/12 11:37
 */
public class LogSkinVolumeDaoImpl extends TempDao {

    public boolean addLogSkinVolumeEmbroideryFix(List<LogSkinVolumeEmbroideryFix> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_skin_volume_embroidery_fix(userId,piecesCount,embroideryMeter,fixTime) VALUES(?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogSkinVolumeEmbroideryFix data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getPiecesCount()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getEmbroideryMeter()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getFixTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogSkinVolumePiecesGet(List<LogSkinVolumePiecesGet> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_skin_volume_pieces_get(userId,skinId,pieces,getWay,getTime) VALUES(?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogSkinVolumePiecesGet data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSkinId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getPieces()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getGetWay()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getGetTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
}
